package com.mycompany.videoclub;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

public class VideoClubSwing extends javax.swing.JFrame {

    public Controlador controlador;
    public List<Pelicula> lista;
    public Pelicula pelicula;
    
    DefaultTableModel modelo;
    
    public boolean opcion=true;
    
    /**
     * Creates new form VideoClubSwing
     */
    public VideoClubSwing() throws Exception {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setTitle("Blackvideo");
        controlador = new Controlador();
        lista = new ArrayList<Pelicula>();
        cargarpelicula("");
    }
    
    public void cargarpelicula(String valor) throws Exception {
        String[] titulos = {"ID", "Nombre", "Descripcion", "Genero", "Director", "Actores_Principales", "Duracion"};
        modelo = new DefaultTableModel(null, titulos);
        String[] fila = new String[7];
        lista = controlador.list(valor);
        if(!lista.isEmpty()){
            for (Pelicula p : lista) {
            fila[0] = String.valueOf(p.getID());
            fila[1] = p.getNombre();
            fila[2] = p.getDescripcion();
            fila[3] = p.getGenero();
            fila[4] = p.getDirector();
            fila[5] = p.getActores_Principales();
            fila[6] = String.valueOf(p.getDuracion());
            modelo.addRow(fila);
        }
        tablapelicula.setModel(modelo);
        TableRowSorter<DefaultTableModel> ordena = new TableRowSorter<DefaultTableModel>(modelo);
        tablapelicula.setRowSorter(ordena);
        }else{
            JOptionPane.showMessageDialog(null, "No hay películas cargadas en la base de datos"); 
            Conectar conexion = new Conectar();
            Connection cn = conexion.conexion();
        }
    }

    public void asignarEntradas() {
        pelicula = new Pelicula();
        pelicula.setNombre(fieldnombre.getText());
        pelicula.setDescripcion(fielddescripcion.getText());
        pelicula.setGenero(fieldgenero.getText());
        pelicula.setDirector(fielddirector.getText());
        pelicula.setActores_Principales(fieldactoresprincipales.getText());
        pelicula.setDuracion(Integer.parseInt(fieldduracion.getText()));           
    }
    
    public void modificarEntradas() {
        pelicula = new Pelicula();
        pelicula.setID(Integer.parseInt(labelcodigo.getText()));
        pelicula.setNombre(fieldnombre.getText());
        pelicula.setDescripcion(fielddescripcion.getText());
        pelicula.setGenero(fieldgenero.getText());
        pelicula.setDirector(fielddirector.getText());
        pelicula.setActores_Principales(fieldactoresprincipales.getText());
        pelicula.setDuracion(Integer.parseInt(fieldduracion.getText()));           
    }
    
    public void insertarpelicula() throws Exception {
        String rpta;
        asignarEntradas();
        rpta = controlador.insert(pelicula);
        if (rpta == null) {
            JOptionPane.showMessageDialog(null, "Pelicula agregada con éxito");
        } else {
            JOptionPane.showMessageDialog(null, "Error en ingreso " + rpta);
        }
    }
    
    public void buscarpelicula(Integer ID) throws Exception {
        pelicula = controlador.getid(ID);
        if( pelicula.getID() != null) {
            labelcodigo.setText(String.valueOf(pelicula.getID()));
            fieldnombre.setText(pelicula.getNombre());
            fielddescripcion.setText(pelicula.getDescripcion());
            fieldgenero.setText(pelicula.getGenero());
            fielddirector.setText(pelicula.getDirector());
            fieldactoresprincipales.setText(pelicula.getActores_Principales());
            fieldduracion.setText(String.valueOf(pelicula.getDuracion()));
        } else {
            JOptionPane.showMessageDialog(null, "Pelicula no encontrada");
        }
    }
    
    public void eliminarpelicula() throws Exception {
        Integer ID=Integer.parseInt(labelcodigo.getText());
        String rpta=controlador.delete(ID);
        if(rpta==null) {
            JOptionPane.showMessageDialog(null, "Pelicula eliminada OK");
        } else {
            JOptionPane.showMessageDialog(null, "Error al eliminar pelicula"+rpta);
        }
    }
    
    public void actualizarpelicula() throws Exception {
        modificarEntradas();
        String rpta=controlador.update(pelicula);
        if (null!=rpta) {
            JOptionPane.showMessageDialog(null, "Error al actualizar "+rpta);
        } else {
            JOptionPane.showMessageDialog(null, "Pelicula Actualizada OK");
        }
    }
    
    public void limpiarEntradas() {
        labelcodigo.setText(null);
        fieldnombre.setText(null);
        fielddescripcion.setText(null);
        fieldgenero.setText(null);
        fielddirector.setText(null);
        fieldactoresprincipales.setText(null);
        fieldduracion.setText(null);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelnombre = new javax.swing.JLabel();
        labeldescripcion = new javax.swing.JLabel();
        labelgenero = new javax.swing.JLabel();
        labeldirector = new javax.swing.JLabel();
        labelactoresprincipales = new javax.swing.JLabel();
        labelduracion = new javax.swing.JLabel();
        fieldnombre = new javax.swing.JTextField();
        fielddescripcion = new javax.swing.JTextField();
        fieldgenero = new javax.swing.JTextField();
        fielddirector = new javax.swing.JTextField();
        fieldactoresprincipales = new javax.swing.JTextField();
        fieldduracion = new javax.swing.JTextField();
        botonalta = new javax.swing.JButton();
        botonmodificar = new javax.swing.JButton();
        botonbaja = new javax.swing.JButton();
        botonlimpiar = new javax.swing.JButton();
        botonbuscar = new javax.swing.JButton();
        labelcodigo = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        botonsalir = new javax.swing.JButton();
        labelfiltro = new javax.swing.JLabel();
        combogenero = new javax.swing.JComboBox();
        fieldfiltro = new javax.swing.JTextField();
        botonvalidardatos = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablapelicula = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("BlackVideo");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("ABM Películas"));
        jPanel1.setName(""); // NOI18N

        labelnombre.setText("Nombre");

        labeldescripcion.setText("Descripción");

        labelgenero.setText("Género");

        labeldirector.setText("Director");

        labelactoresprincipales.setText("Actores Principales");

        labelduracion.setText("Duración");

        fieldnombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fieldnombreActionPerformed(evt);
            }
        });

        fieldduracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fieldduracionActionPerformed(evt);
            }
        });

        botonalta.setText("Alta");
        botonalta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonaltaActionPerformed(evt);
            }
        });

        botonmodificar.setText("Modificar");
        botonmodificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonmodificarActionPerformed(evt);
            }
        });

        botonbaja.setText("Baja");
        botonbaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonbajaActionPerformed(evt);
            }
        });

        botonlimpiar.setText("Limpiar");
        botonlimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonlimpiarActionPerformed(evt);
            }
        });

        botonbuscar.setText("Buscar");
        botonbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonbuscarActionPerformed(evt);
            }
        });

        jLabel1.setText("Código Pelicula");

        botonsalir.setText("Salir");
        botonsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonsalirActionPerformed(evt);
            }
        });

        labelfiltro.setText("Filtro");

        combogenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acción", "Comedia", "Drama", "Suspenso", "Terror", "Otro" }));
        combogenero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combogeneroActionPerformed(evt);
            }
        });

        fieldfiltro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                fieldfiltroKeyReleased(evt);
            }
        });

        botonvalidardatos.setText("Validar Datos");
        botonvalidardatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonvalidardatosActionPerformed(evt);
            }
        });

        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("Debe Validar Datos antes de realizar ABM de peliculas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(labelfiltro)
                                .addGap(18, 18, 18)
                                .addComponent(fieldfiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(botonalta)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonmodificar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonbaja)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonlimpiar)
                                .addGap(81, 81, 81)
                                .addComponent(botonsalir))
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelactoresprincipales)
                                    .addComponent(labelduracion))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(fieldduracion, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(botonvalidardatos))
                                    .addComponent(fieldactoresprincipales, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(fielddescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelnombre)
                                    .addComponent(labeldescripcion)
                                    .addComponent(labelgenero)
                                    .addComponent(labeldirector))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(66, 66, 66)
                                        .addComponent(fieldnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(fieldgenero, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(fielddirector, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                                .addComponent(botonbuscar))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(97, 97, 97)
                                        .addComponent(labelcodigo))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(combogenero, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 0, Short.MAX_VALUE))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelnombre)
                            .addComponent(fieldnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(botonbuscar))
                        .addGap(4, 4, 4)
                        .addComponent(labelcodigo)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labeldescripcion)
                    .addComponent(fielddescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelgenero)
                    .addComponent(fieldgenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(combogenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labeldirector)
                    .addComponent(fielddirector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelactoresprincipales)
                    .addComponent(fieldactoresprincipales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelduracion)
                    .addComponent(fieldduracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonvalidardatos))
                .addGap(16, 16, 16)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonsalir)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botonbaja)
                        .addComponent(botonmodificar)
                        .addComponent(botonalta)
                        .addComponent(botonlimpiar)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelfiltro)
                    .addComponent(fieldfiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        tablapelicula.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Nombre", "Descripcion", "Genero", "Director", "Actores_Principales", "Duracion"
            }
        ));
        jScrollPane2.setViewportView(tablapelicula);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 68, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonlimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonlimpiarActionPerformed
        limpiarEntradas();
    }//GEN-LAST:event_botonlimpiarActionPerformed

    private void fieldnombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldnombreActionPerformed
    }//GEN-LAST:event_fieldnombreActionPerformed

    private void botonaltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonaltaActionPerformed
        try {
            insertarpelicula();
            cargarpelicula("");
        } catch (Exception ex) {
            Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_botonaltaActionPerformed

    private void botonmodificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonmodificarActionPerformed
        try {
            actualizarpelicula();
            cargarpelicula("");
        } catch (Exception ex) {
            Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
        }       
    }//GEN-LAST:event_botonmodificarActionPerformed

    private void botonbajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonbajaActionPerformed
        try {
            eliminarpelicula();
            cargarpelicula("");
        } catch (Exception ex) {
            Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_botonbajaActionPerformed

    private void botonbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonbuscarActionPerformed
        try {
            Integer id = Integer.valueOf(JOptionPane.showInputDialog("Ingrese codigo de pelicula"));
            buscarpelicula(id);
        } catch (Exception ex){
            Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_botonbuscarActionPerformed

    private void botonsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonsalirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_botonsalirActionPerformed

    private void combogeneroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combogeneroActionPerformed
        String opcion = new String();
        opcion = (String) combogenero.getSelectedItem();
        if(opcion.equals("Otro")){
            fieldgenero.setEnabled(true);
            fieldgenero.setEditable(true);
            fieldgenero.setText("Ingrese género");
        } else{
            fieldgenero.setText((String) combogenero.getSelectedItem());
        }
    }//GEN-LAST:event_combogeneroActionPerformed

    private void fieldduracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldduracionActionPerformed
    }//GEN-LAST:event_fieldduracionActionPerformed

    private void fieldfiltroKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldfiltroKeyReleased
        String filtro = fieldfiltro.getText();
        try {
            cargarpelicula(filtro);
        } catch (Exception ex) {
            Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_fieldfiltroKeyReleased

    private void botonvalidardatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonvalidardatosActionPerformed
        String duracion = new String();
        duracion = fieldduracion.getText();
        if (duracion.equals("0")){
            JOptionPane.showMessageDialog(null, "La duración debe ser mayor a cero.");
            fieldduracion.requestFocus();
        } else{
            JOptionPane.showMessageDialog(null, "Datos validados correctamente");
        }
    }//GEN-LAST:event_botonvalidardatosActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VideoClubSwing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VideoClubSwing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VideoClubSwing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VideoClubSwing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new VideoClubSwing().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(VideoClubSwing.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonalta;
    private javax.swing.JButton botonbaja;
    private javax.swing.JButton botonbuscar;
    private javax.swing.JButton botonlimpiar;
    private javax.swing.JButton botonmodificar;
    private javax.swing.JButton botonsalir;
    private javax.swing.JButton botonvalidardatos;
    private javax.swing.JComboBox combogenero;
    private javax.swing.JTextField fieldactoresprincipales;
    private javax.swing.JTextField fielddescripcion;
    private javax.swing.JTextField fielddirector;
    private javax.swing.JTextField fieldduracion;
    private javax.swing.JTextField fieldfiltro;
    private javax.swing.JTextField fieldgenero;
    private javax.swing.JTextField fieldnombre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelactoresprincipales;
    private javax.swing.JLabel labelcodigo;
    private javax.swing.JLabel labeldescripcion;
    private javax.swing.JLabel labeldirector;
    private javax.swing.JLabel labelduracion;
    private javax.swing.JLabel labelfiltro;
    private javax.swing.JLabel labelgenero;
    private javax.swing.JLabel labelnombre;
    private javax.swing.JTable tablapelicula;
    // End of variables declaration//GEN-END:variables
}